package com.lcy.reggie.controller;

/**
 * ======刘春春大帅逼======
 * ******java学习之旅******
 */

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcy.reggie.common.Result;
import com.lcy.reggie.dto.DishDto;
import com.lcy.reggie.entity.Dish;
import com.lcy.reggie.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  菜品管理类
 */
@RestController
@RequestMapping("/dish")
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 分页查询
     */
    @GetMapping("/page")
    public Result<Page> pageResult(Integer page,Integer pageSize,String name){
        return dishService.pageResult(page,pageSize,name);
    }

    /**
     * 新增菜品
     */
    @PostMapping
    public Result<String> save(@RequestBody DishDto dishDto){
        return dishService.saveDish(dishDto);
    }

    /**
     *  修改菜品时回显菜品信息
     */
    @GetMapping("/{id}")
    public Result<DishDto> selectById(@PathVariable Long id){
        return dishService.selectById(id);
    }


    /**
     *  修改菜品
     */
    @PutMapping
    public Result<String> update(@RequestBody DishDto dishDto){
        return dishService.update(dishDto);
    }

    /**
     *  删除/批量删除 菜品
     */
    @DeleteMapping()
    public Result<String> deleteById(@RequestParam("ids")List<Long> id){
        return dishService.deleteById(id);
    }

    /**
     * 修改/批量修改 售卖状态
     */
    @PostMapping("/status/{status}")
    public Result<String> updateStatus(@PathVariable Integer status, @RequestParam("ids") List<Long> id){
        return dishService.updateStatus(status,id);
    }


    /**
     *  套餐管理下的添加菜品回显
     */
    @GetMapping("/list")
    public Result<List<DishDto>> list(Dish dish){
        return dishService.list(dish);
    }
}
